package com.lanou.wuyou.one;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.lanou.wuyou.one.call.CallFragment;
import com.lanou.wuyou.one.contacts.ContactsFragment;
import com.lanou.wuyou.one.note.NoteFragment;
import com.lanou.wuyou.one.records.RecordsFragment;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private List<Fragment> fragments;
    private MainAdapter adapter;
    private ViewPager viewPager;
    private TabLayout tabLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fragments = new ArrayList<>();
        fragments.add(new CallFragment());
        fragments.add(new RecordsFragment());
        fragments.add(new ContactsFragment());
        fragments.add(new NoteFragment());

        viewPager = (ViewPager) findViewById(R.id.view_pager);
        tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        adapter = new MainAdapter(getSupportFragmentManager(),fragments);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

        for (int i = 0; i < adapter.getCount(); i++) {
            View tabView = adapter.getTabView(i,this);
            TabLayout.Tab tan = tabLayout.getTabAt(i);
            tan.setCustomView(tabView);
        }
    }
}
